/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "构建物理节点.h"
#include <场景/intern/S_Scene.h>

#include "节点/物理/粒子发射器.h"
#include "节点/物理/物理体.h"
#include "节点/物理/物理力.h"
#include "节点/物理/解算器.h"
#include "框架/工作区/工作区.h"

#include <Context/当前默认操作数据.h>



#include "A_引擎/引擎.h"



#include <节点/插座/C_矢量插座.h>
#include <节点/插座/list/list数值插座.h>
#include <节点/插座/list/list物体插座.h>



static void on_切换物体类型(S_Props& prop) {
	//switch ((*(S_PropValueEnum*)prop.m_Value).m_当前选项)
	auto nodes = f_global_get激活节点();
	for (auto 节点 : nodes) {
		节点->f_set是否要更新(true);
	}
}

static void on_切换计算GPU(S_Props& prop) {
	//switch ((*(S_PropValueEnum*)prop.m_Value).m_当前选项)
	auto nodes = f_global_get激活节点();
	for (auto 节点 : nodes) {
		节点->f_set是否要更新(true);
	}
}


static void on_物理引擎模型读写更新节点(S_Props& prop) {
	E_对话框类型 类型 = E_对话框类型::e_读取;

	auto nodes = f_global_get激活节点();
	

	f_ui_set路径编辑框对话框类型(prop.m_UI->m_部件, 类型);
	f_ui_set路径编辑框对话框后缀(prop.m_UI->m_部件, ".xml");

	if (f_ui_路径编辑框是否打开(prop.m_UI->m_部件)) {
		for (auto 节点 : nodes) {
			节点->f_set是否要更新(true);
		}
	}

}


static void on_参数修改_路径变更(S_Props& prop) {
	//auto nodes = f_global_get激活节点();
	f_ui_set路径编辑框对话框类型(prop.m_UI->m_部件, E_对话框类型::e_打开路径);
	//prop.m_UI->m_部件;

}

static void on_参数修改_物理体名称修改(S_Props& prop) {
	auto nodes = f_global_get激活节点();
	for (auto& node : nodes) {
		C_粒子系统节点* pn = dynamic_cast<C_粒子系统节点*>(node);
		if (pn) {
			f_prop_LineStr(prop) = f_node_物体名称修改(pn->m_物理体, f_prop_LineStr(prop));
		}
	}
	prop.m_UI->m_部件->m_更新绘制属性 = true;
	prop.m_UI->m_部件->m_父部件->m_更新绘制属性 = true;
	f_节点参数更新(prop);
}




static void f_粒子系统_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_粒子系统节点* node = dynamic_cast<C_粒子系统节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_系统名称.m_UI->m_Update = on_参数修改_物理体名称修改;
	props.push_back(node->m_系统名称);

	node->m_包含属性.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_包含属性);

	node->m_粒子数量.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_粒子数量);

	node->m_渲染类型.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_渲染类型);

	node->m_粒子寿命.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_粒子寿命);

	node->m_寿命随机比.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_寿命随机比);


	node->m_随机大小.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_随机大小);

	if (f_prop_Bool(node->m_随机大小)) {
		node->m_随机大小区间.m_UI->m_Update = f_节点参数更新;
		props.push_back(node->m_随机大小区间);
	}
	else {
		node->m_粒子大小.m_UI->m_Update = f_节点参数更新;
		props.push_back(node->m_粒子大小);
	}

	

	node->m_坐标属性名称.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_坐标属性名称);

	node->m_旋转属性名称.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_旋转属性名称);

	node->m_速度属性名称.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_速度属性名称);

	node->m_大小属性名称.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_大小属性名称);

	node->m_寿命属性名称.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_寿命属性名称);

	node->m_年龄属性名称.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_年龄属性名称);


	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_粒子系统(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_粒子系统节点(ctx_3d);
		node->m_ICO = u"icoVecSphere0009";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_粒子系统(plane, node);
	return plane;
}

void f_节点重置_粒子系统(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_粒子系统_部件构建属性;
	plane->m_ICO = node->m_ICO;
}








C_节点面板* f_节点构建_点粒子发射(S_UI渲染环境& ctx) {
	//C_粒子节点* node = new C_粒子节点();

	//C_节点面板* nodeplane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_物体);

	return 0;
}







static void f_圆面粒子发射_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_面粒子发射节点* node = dynamic_cast<C_面粒子发射节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_圆面粒子发射(S_UI渲染环境& ctx, C_节点基类* node) {
	if (!node) node = new C_面粒子发射节点(*S_节点框架::g_3D视口环境);

	C_节点面板* nodeplane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_物体);
	nodeplane->m_属性面板参数构建 = f_圆面粒子发射_部件构建属性;
	nodeplane->m_ICO = u"magicwand";

	f_NodeCtx_get默认场景()->f_add物体(dynamic_cast<C_面粒子发射节点*>(node)->m_发射体物体);

	return nodeplane;
}

void f_节点重置_圆面粒子发射(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_圆面粒子发射_部件构建属性;
	plane->m_ICO = u"magicwand";
}




static void on_清除物理引擎缓存(S_Props& prop) {
	f_节点参数更新(prop);
	f_工作区_联动更新(E_工作区类型::e_节点视口, E_工作区操作类型::e_更新节点);
}


static void f_物理引擎节点_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_物理引擎节点* node = dynamic_cast<C_物理引擎节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_物理引擎类型.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_物理引擎类型);

	node->m_模型读写路径.m_UI->m_Update = on_物理引擎模型读写更新节点;
	props.push_back(node->m_模型读写路径);

	switch (E_物理引擎(f_prop_enum(node->m_物理引擎类型))) {
		case E_物理引擎::E_物理引擎_Mujoco:{
			break;
		}
		case E_物理引擎::E_物理引擎_PBF: 
		case E_物理引擎::E_物理引擎_MPM: {
			node->m_域大小.m_UI->m_Update = f_节点参数更新;
			props.push_back(node->m_域大小);

			node->m_单元大小.m_UI->m_Update = f_节点参数更新;
			props.push_back(node->m_单元大小);
			break;
		}
		default:
			break;
	}

	node->m_清除所有缓存.m_UI->m_Update = on_清除物理引擎缓存;
	props.push_back(node->m_清除所有缓存);
	//node->m_重置时间.m_UI->m_Update = on_物理引擎模型读写更新节点;
	//props.push_back(node->m_重置时间);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理引擎(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_物理引擎节点(ctx_3d, tree);
		node->m_ICO = u"icoVecSphere0009";
	}
	//if (plane == nullptr) {
	//	plane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_节点视图);
	//	plane->m_属性面板参数构建 = f_物理引擎节点_部件构建属性;
	//}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物理引擎(plane, node);
	return plane;
}

void f_节点重置_物理引擎(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_节点视图);
	plane->m_属性面板参数构建 = f_物理引擎节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}










static void f_物理体_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_物理体节点* node = dynamic_cast<C_物理体节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	//node->m_物理引擎类型.m_UI->m_Update = on_切换物体类型;
	//props.push_back(node->m_物理引擎类型);

	node->m_物理体类型.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_物理体类型);

	node->m_粒子最大数.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_粒子最大数);

	node->m_填充方式.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_填充方式);

	//if (node->f_get输入插座(2)->f_isLink()) {
	//	
	//}
	node->m_链接类型.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_链接类型);

	node->m_链接轴向.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_链接轴向);
	
	node->m_限定范围.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_限定范围);

	node->m_关节范围.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_关节范围);

	node->m_关节阻尼.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_关节阻尼);

	node->m_关节刚度.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_关节刚度);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理体(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_物理体节点(ctx_3d);
		node->m_ICO = u"genius";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物理体(plane, node);
	return plane;
}

void f_节点重置_物理体(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_物理体_部件构建属性;
	plane->m_ICO = node->m_ICO;
}




static void f_物理几何体节点_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_物理几何体节点* node = dynamic_cast<C_物理几何体节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_几何体类型.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_几何体类型);

	node->m_重量.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_重量);

	node->m_密度.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_密度);

	//node->m_弹性.m_UI->m_Update = on_切换物体类型;
	//props.push_back(node->m_弹性);

	node->m_阻尼.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_阻尼);

	node->m_边缘距离.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_边缘距离);

	node->m_摩擦.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_摩擦);

	node->m_旋转惯性.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_旋转惯性);

	node->m_接触参考.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_接触参考);

	node->m_接触实施.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_接触实施);

	node->m_接触混合.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_接触混合);

	node->m_碰撞位掩码.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_碰撞位掩码);

	node->m_接触的频率.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_接触的频率);

	node->m_接触自由度.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_接触自由度);



	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理几何体(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_物理几何体节点(ctx_3d);
		node->m_ICO = u"ico_物理几何体0000";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物理几何体(plane, node);
	return plane;
}

void f_节点重置_物理几何体(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_物理几何体节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}




static void f_物理体添加_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_物理体添加节点* node = dynamic_cast<C_物理体添加节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理体添加(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_物理体添加节点(ctx_3d);
		node->m_ICO = u"genius";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物理体添加(plane, node);
	return plane;
}

void f_节点重置_物理体添加(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_物理体添加_部件构建属性;
	plane->m_ICO = node->m_ICO;
}



static void f_取物理体节点_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_取物理体节点* node = dynamic_cast<C_取物理体节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);
	node->m_物理几何类型.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_物理几何类型);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_取物理体节点(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_取物理体节点(ctx_3d);
		node->m_ICO = u"genius";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_取物理体节点(plane, node);
	return plane;
}

void f_节点重置_取物理体节点(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_取物理体节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}



static void f_物理体绑定物体节点_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_物理体绑定物体节点* node = dynamic_cast<C_物理体绑定物体节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理体绑定物体节点(S_UI渲染环境& ctx, S_设备环境& view_ctx, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_物理体绑定物体节点(view_ctx);
		node->m_ICO = u"genius";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物理体绑定物体节点(plane, node);
	return plane;
}

void f_节点重置_物理体绑定物体节点(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_物理体绑定物体节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}




static void f_物理引擎内部几何节点_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_物理引擎内部几何节点* node = dynamic_cast<C_物理引擎内部几何节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理引擎内部几何节点(S_UI渲染环境& ctx, S_设备环境& view_ctx, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) node = new C_物理引擎内部几何节点(view_ctx);
	//if (plane == nullptr) {
	//	plane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_节点视图);
	//	plane->m_属性面板参数构建 = f_物理引擎内部几何节点_部件构建属性;
	//}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物理体绑定物体节点(plane, node);
	return plane;
}

void f_节点重置_物理引擎内部几何节点(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_物理引擎内部几何节点_部件构建属性;
	plane->m_ICO = u"genius";
}










static void f_物理单方向力_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_单方向物理力节点* node = dynamic_cast<C_单方向物理力节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理单方向力(S_UI渲染环境& ctx, C_节点基类* node) {
	if (!node) node = new C_单方向物理力节点(*S_节点框架::g_3D视口环境);
	C_节点面板* nodeplane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_物体);
	nodeplane->m_属性面板参数构建 = f_物理单方向力_部件构建属性;
	nodeplane->m_ICO = u"genius";
	return nodeplane;
}

void f_节点重置_物理单方向力(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_物理单方向力_部件构建属性;
	plane->m_ICO = u"genius";
}




static void f_物理应用力_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_应用力节点* node = dynamic_cast<C_应用力节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_力方式.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_力方式);

	S_节点数据::g_物理引擎视口互交.m_UI->m_Update = on_切换物体类型;
	props.push_back(S_节点数据::g_物理引擎视口互交);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物理应用力(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_应用力节点(ctx_3d);
		node->m_ICO = u"应用力";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物理应用力(plane, node);
	return plane;
}

void f_节点重置_物理应用力(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_物理应用力_部件构建属性;
	plane->m_ICO = node->m_ICO;
}





static void f_设置肌腱力度_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_更新肌腱节点* node = dynamic_cast<C_更新肌腱节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	props.push_back(S_节点数据::g_物理引擎视口互交);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_更新肌腱力度(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_更新肌腱节点(ctx_3d);
		node->m_ICO = u"genius";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_更新肌腱力度(plane, node);
	return plane;
}

void f_节点重置_更新肌腱力度(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_设置肌腱力度_部件构建属性;
	plane->m_ICO = node->m_ICO;
}








static void f_发射节点_3D视口更新(C_节点面板* node, S_Scene* scene) {
	C_发射节点* 网格节点 = dynamic_cast<C_发射节点*>(node->m_NodeData);

}

static void f_发射节点_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_发射节点* node = dynamic_cast<C_发射节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_发射方式.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_发射方式);
	node->m_粒子系统.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_粒子系统);
	
	plane->f_构建属性部件(props);

	//f_发射节点_3D视口更新(((C_节点面板*)obj), nullptr);
}

C_节点面板* f_节点构建_发射(S_UI渲染环境& ctx, S_设备环境& view_ctx, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_发射节点(view_ctx);
		node->m_ICO = u"genius";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_发射(plane, node);
	return plane;
}

void f_节点重置_发射(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_节点视图);
	plane->m_属性面板参数构建 = f_发射节点_部件构建属性;
	plane->m_3D视口更新 = f_发射节点_3D视口更新;
	plane->m_ICO = node->m_ICO;
}










static void f_FLIP解算器_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_FLIP解算器节点* node = dynamic_cast<C_FLIP解算器节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_FLIP解算器(S_UI渲染环境& ctx, C_节点基类* node) {
	if (!node) node = new C_FLIP解算器节点(E_物理引擎::E_物理引擎_FLIP, *S_节点框架::g_3D视口环境);

	C_节点面板* nodeplane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_物体);
	nodeplane->m_属性面板参数构建 = f_FLIP解算器_部件构建属性;
	nodeplane->m_ICO = u"voxel_n1";

	return nodeplane;
}

void f_节点重置_FLIP解算器(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_FLIP解算器_部件构建属性;
	plane->m_ICO = u"voxel_n1";
}







static void f_PBF解算器_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_PBF解算器节点* node = dynamic_cast<C_PBF解算器节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	S_Props prop;

	node->m_物理引擎类型.m_UI->m_Update = on_切换物体类型;
	props.push_back(node->m_物理引擎类型);

	node->m_GPU.m_UI->m_Update = on_切换计算GPU;
	props.push_back(node->m_GPU);
	
	node->m_飞溅粒子数量.m_UI->m_Update = on_切换计算GPU;
	props.push_back(node->m_飞溅粒子数量);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_PBF解算器(S_UI渲染环境& ctx, S_设备环境& view_ctx, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) node = new C_PBF解算器节点(view_ctx);
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_PBF解算器(plane, node);
	return plane;
}
void f_节点重置_PBF解算器(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_PBF解算器_部件构建属性;
	plane->m_ICO = u"icoVecSphere0009";
}





static void f_FleX解算器_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_PBF参数节点* node = dynamic_cast<C_PBF参数节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_迭代次数.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_迭代次数);
	node->m_粒子半径.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_粒子半径);
	node->m_固体重置距离.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_固体重置距离);
	node->m_流体重置距离.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_流体重置距离);

	node->m_最大速度.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_最大速度);
	node->m_最大加速度.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_最大加速度);

	node->m_风向.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_风向);
	node->m_布料拖拽.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_布料拖拽);
	node->m_空气阻力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_空气阻力);

	node->m_动态摩擦.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_动态摩擦);
	node->m_静态摩擦.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_静态摩擦);
	node->m_粒子摩擦.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_粒子摩擦);
	node->m_碰撞重置.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_碰撞重置);
	node->m_附着力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_附着力);
	node->m_休眠.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_休眠);
	
	node->m_传播收敛.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_传播收敛);
	node->m_消散.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_消散);
	node->m_阻力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_阻力);

	node->m_凝聚性.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_凝聚性);
	node->m_表面张力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_表面张力);
	node->m_粘度.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_粘度);
	node->m_涡流.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_涡流);
	node->m_流体球拉伸大小.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_流体球拉伸大小);
	node->m_流体球拉伸最小.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_流体球拉伸最小);
	node->m_流体球拉伸最大.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_流体球拉伸最大);
	node->m_平滑强度.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_平滑强度);
	node->m_固体压力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_固体压力);
	node->m_边界阻力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_边界阻力);
	node->m_浮力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_浮力);

	node->m_飞溅产生.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_飞溅产生);
	node->m_飞溅浮力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_飞溅浮力);
	node->m_飞溅阻力.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_飞溅阻力);
	node->m_飞溅发射.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_飞溅发射);
	node->m_飞溅寿命.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_飞溅寿命);

	node->m_碰撞距离.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_碰撞距离);
	node->m_碰撞距离边缘.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_碰撞距离边缘);
	node->m_碰撞形状边缘.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_碰撞形状边缘);
	node->m_松弛.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_松弛);
	node->m_松弛模式.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_松弛模式);


	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_FleX参数(S_UI渲染环境& ctx, S_设备环境& view_ctx, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_PBF参数节点(view_ctx);
		node->m_ICO = u"ico_NVIDIA_FleX0018";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_FleX参数(plane, node);
	return plane;
}

void f_节点重置_FleX参数(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_FleX解算器_部件构建属性;
	plane->m_ICO = node->m_ICO;
}









static void f_解算器更新_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_解算器更新节点* node = dynamic_cast<C_解算器更新节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	S_Props prop;
	
	node->m_重置时间.m_UI->m_Update = on_物理引擎模型读写更新节点;
	props.push_back(node->m_重置时间);

	props.push_back(node->m_是否多线程);
	props.push_back(node->m_时间区间);
	
	props.push_back(node->m_时间步进);
	props.push_back(node->m_子帧);

	props.push_back(node->m_变换物体);

	node->m_是否缓存.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_是否缓存);
	if (f_prop_Bool(node->m_是否缓存)) {
		
		node->m_缓存路径.m_UI->m_Update = on_参数修改_路径变更;
		props.push_back(node->m_缓存路径);
		props.push_back(node->m_文件名);
		props.push_back(node->m_缓存压缩);
		props.push_back(node->m_缓存方式);
		
		props.push_back(node->m_清除当前帧后缓存);


		node->m_保留缓存设备.m_UI->m_Update = f_节点参数更新_属性栏更新;
		props.push_back(node->m_保留缓存设备);
		
		if (f_prop_enum(node->m_保留缓存设备) != 0) {
			props.push_back(node->m_保留缓存数量);
		}
	}
	
	node->m_可视项.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_可视项);

	props.push_back(node->m_视口互交);
	node->m_视口互交.m_UI->m_Update = on_参数修改_路径变更;

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_解算器模拟(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_解算器更新节点(ctx_3d);
		node->m_ICO = u"icoVecSphere0009";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_解算器模拟(plane, node);
	return plane;
}

void f_节点重置_解算器模拟(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_解算器更新_部件构建属性;
	plane->m_ICO = node->m_ICO;
}







static void f_作用力_部件构建属性(C_属性栏* plane, S_结构指针 obj) {
	C_力对象节点* node = dynamic_cast<C_力对象节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	S_Props prop;
	node->m_力类型.m_UI->m_Update = f_节点参数更新;
	props.push_back(node->m_力类型);

	node->m_使用范围.m_UI->m_Update = f_节点参数更新_属性栏更新;
	props.push_back(node->m_使用范围);
	if (f_prop_Bool(node->m_使用范围)) {
		node->m_范围形状.m_UI->m_Update = f_节点参数更新_属性栏更新;
		props.push_back(node->m_范围形状);

		node->m_最小范围.m_UI->m_Update = f_节点参数更新;
		props.push_back(node->m_最小范围);

		node->m_最大范围.m_UI->m_Update = f_节点参数更新;
		props.push_back(node->m_最大范围);

		if (f_prop_enum(node->m_范围形状) == 1) {
			node->m_范围最小高度.m_UI->m_Update = f_节点参数更新;
			props.push_back(node->m_范围最小高度);

			node->m_范围最大高度.m_UI->m_Update = f_节点参数更新;
			props.push_back(node->m_范围最大高度);
		}
	}
	

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_作用力(S_UI渲染环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree, const std::u16string& name) {
	if (!node) {
		node = new C_力对象节点(ctx_3d);
		node->m_ICO = u"icoVecSphere0009";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_作用力(plane, node);
	return plane;
}

void f_节点重置_作用力(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_作用力_部件构建属性;
	plane->m_ICO = node->m_ICO;
}







void f_物理节点_构建函数初始化() {
	C_节点面板::g节点面板构建函数[DEF_发射节点] = f_节点构建_发射;
	C_节点面板::g节点面板重置函数[DEF_发射节点] = f_节点重置_发射;
	C_节点面板::g节点构建函数_创建名称对应类型名称[u"粒子发射"] = DEF_发射节点;

	C_节点面板::g节点面板构建函数[DEF_粒子系统节点] = f_节点构建_粒子系统;
	C_节点面板::g节点面板重置函数[DEF_粒子系统节点] = f_节点重置_粒子系统;
	C_节点面板::g节点构建函数_创建名称对应类型名称[u"粒子系统"] = DEF_粒子系统节点;

	C_节点面板::g节点面板构建函数[DEF_PBF参数] = f_节点构建_FleX参数;
	C_节点面板::g节点面板重置函数[DEF_PBF参数] = f_节点重置_FleX参数;
	C_节点面板::g节点构建函数_创建名称对应类型名称[u"PBF参数"] = DEF_PBF参数;

	C_节点面板::g节点面板构建函数[DEF_作用力节点] = f_节点构建_作用力;
	C_节点面板::g节点面板重置函数[DEF_作用力节点] = f_节点重置_作用力;
	C_节点面板::g节点构建函数_创建名称对应类型名称[u"力"] = DEF_作用力节点;

}




bool f_物理节点重构(C_节点面板** plane, C_节点基类* node, S_UI渲染环境* ctx) {

	if (node->m_TypeName == "粒子节点") {
		if (!plane[0]) plane[0] = f_节点构建_粒子系统(*ctx, *S_节点框架::g_3D视口环境, node);
		else f_节点重置_粒子系统(plane[0], node);
	}
	else if (node->m_TypeName == "面粒子发射节点") {
		if (!plane[0]) plane[0] = f_节点构建_圆面粒子发射(*ctx, node);
		else f_节点重置_圆面粒子发射(plane[0], node);
	}
	else if (node->m_TypeName == "物理体节点") {
		if (!plane[0]) plane[0] = f_节点构建_物理体(*ctx, *S_节点框架::g_3D视口环境, node);
		else f_节点重置_物理体(plane[0], node);
	}
	else if (node->m_TypeName == "PBF解算器节点") {
		if (!plane[0]) plane[0] = f_节点构建_PBF解算器(*ctx, *S_节点框架::g_3D视口环境, node);
		else f_节点重置_PBF解算器(plane[0], node);
	}
	else if (node->m_TypeName == "FleX参数节点") {
		if (!plane[0]) plane[0] = f_节点构建_FleX参数(*ctx, *S_节点框架::g_3D视口环境, node);
		else f_节点重置_FleX参数(plane[0], node);
	}
	else if (node->m_TypeName == "发射节点") {
		if (!plane[0]) plane[0] = f_节点构建_发射(*ctx, *S_节点框架::g_3D视口环境, node);
		else f_节点重置_发射(plane[0], node);
	}
	else if (node->m_TypeName == "解算器更新节点") {
		if (!plane[0]) plane[0] = f_节点构建_解算器模拟(*ctx, *S_节点框架::g_3D视口环境, node);
		else f_节点重置_解算器模拟(plane[0], node);
	}
	else {
		return false;
	}

	return true;
}





